package com.beyondsoft.mcms.web;

import org.springframework.core.convert.converter.Converter;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
import org.springframework.roo.addon.web.mvc.controller.converter.RooConversionService;

import com.beyondsoft.mcms.domain.Conference;
import com.beyondsoft.mcms.domain.Document;
import com.beyondsoft.mcms.domain.Item;
import com.beyondsoft.mcms.domain.MemberInfo;
import com.beyondsoft.mcms.reference.AuthRole;

/**
 * A central place to register application converters and formatters. 
 */
@RooConversionService
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {

	@Override
	protected void installFormatters(FormatterRegistry registry) {
		super.installFormatters(registry);
		// Register application converters and formatters
	}
	
    public Converter<Item, String> getItemToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.beyondsoft.mcms.domain.Item, java.lang.String>() {
            public String convert(Item item) {
            	if (item.getIsValid()){
            		return new StringBuilder().append(item.getName()).toString();
            	}
            	else{ return "";}
            }
        };
    }
    
    public Converter<Conference, String> getConferenceToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.beyondsoft.mcms.domain.Conference, java.lang.String>() {
            public String convert(Conference conference) {
                return new StringBuilder().append(conference.getName()).toString();
            }
        };
    }
    
    
    public Converter<Document, String> getDocumentToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.beyondsoft.mcms.domain.Document, java.lang.String>() {
            public String convert(Document document) {
                return new StringBuilder().append(document.getName()).append(' ').append(document.getFileName()).toString();
            }
        };
    }
    
    
    public Converter<MemberInfo, String> getMemberInfoToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<com.beyondsoft.mcms.domain.MemberInfo, java.lang.String>() {
            public String convert(MemberInfo memberInfo) {
                return new StringBuilder().append(memberInfo.getMemberName()).toString();
            }
        };
    }
    
    public Converter<AuthRole, String> getAuthRoleToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<AuthRole, java.lang.String>() {
            public String convert(AuthRole authRole) {
                return authRole.toString();
            }
        };
    }
    
    
    public void installLabelConverters(FormatterRegistry registry) {
        registry.addConverter(getAttendeeToStringConverter());
        registry.addConverter(getIdToAttendeeConverter());
        registry.addConverter(getStringToAttendeeConverter());
        registry.addConverter(getCategoryToStringConverter());
        registry.addConverter(getIdToCategoryConverter());
        registry.addConverter(getStringToCategoryConverter());
        registry.addConverter(getConferenceToStringConverter());
        registry.addConverter(getIdToConferenceConverter());
        registry.addConverter(getStringToConferenceConverter());
        registry.addConverter(getDocumentToStringConverter());
        registry.addConverter(getIdToDocumentConverter());
        registry.addConverter(getStringToDocumentConverter());
        registry.addConverter(getFeeToStringConverter());
        registry.addConverter(getIdToFeeConverter());
        registry.addConverter(getStringToFeeConverter());
        registry.addConverter(getGroupInfoToStringConverter());
        registry.addConverter(getIdToGroupInfoConverter());
        registry.addConverter(getStringToGroupInfoConverter());
        registry.addConverter(getItemToStringConverter());
        registry.addConverter(getIdToItemConverter());
        registry.addConverter(getStringToItemConverter());
        registry.addConverter(getMemberInfoToStringConverter());
        registry.addConverter(getIdToMemberInfoConverter());
        registry.addConverter(getStringToMemberInfoConverter());
        registry.addConverter(getSuggestToStringConverter());
        registry.addConverter(getIdToSuggestConverter());
        registry.addConverter(getStringToSuggestConverter());
        registry.addConverter(getUsersToStringConverter());
        registry.addConverter(getIdToUsersConverter());
        registry.addConverter(getStringToUsersConverter());
        registry.addConverter(getAuthRoleToStringConverter());
        
    }
}
